import 'package:flutter/material.dart';

class ChildCase extends StatefulWidget {
  const ChildCase({ Key? key,required this.count,required this.updateCallBack }) : super(key: key);

final int count;
final Function(int) updateCallBack;  // 接收一个回调函数
  @override
  _ChildCaseState createState() => _ChildCaseState();
}

class _ChildCaseState extends State<ChildCase> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Text('父组件传递过来的值${widget.count}',
        style: TextStyle(fontSize: 40)),
        ElevatedButton(onPressed: (){
          // 实现子传父
              //  widget.count+1 // 子传父
          widget.updateCallBack(widget.count+1);
        }, child: Text('点击'))
      ],
    );
  }
}